package lab03.test06;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.Map;
import java.util.RandomAccess;

/**
 * Created by JAVA on 2017/12/1.
 */
public class Test {
    public static void main(String[] args) {
        String path="D:\\words.txt";
        try {
            RandomAccessFile file=new RandomAccessFile(path,"rw");
            String line=null;

            Map<String,Integer> map=new HashMap<>();
            try {
                file =new RandomAccessFile(path,"r");
             //   String line = null;
                     line=null;

                while((line=file.readLine())!=null){
                    System.out.println(line);
                    //先判断map中有没有这个key,没有直接将value赋值为1
                    if(map.get(line)==null){
                        map.put(line,1);
                    }else {
                      int value=  map.get(line);
                      value=value+1;
                      map.put(line,value);
                      map.put(line,map.get(line)+1);


                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            ;
            //map
            //key--value(string----int)
            //hello   2
            //world   1
            //study   1
            //man     0
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {

        }

    }
}
